<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" session="false" %>
<%@ page import="com.atozsoft.commonutil.Constants"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.SimpleDateFormat"%>
	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- 
  - Author(s): houfy
  - Date: 2014-11-13 09:12:31
  - Description:
-->
<head>
    <%@include file="/common.jsp"%>
	<%@include file="/common/common.jsp"%>
    <%@include file="/coframe/tools/skins/common.jsp" %>
	<title>流程管理</title>
</head>
<body>
	<div id="layout1" class="nui-layout" style="width:100%;height:100%;">
		<div title="流程管理" region="west" bodyStyle="overflow:hidden;" width="260" 
			class="sub-sidebar" allowResize="false">
            <div showCollapseButton="true" style="border-width:1px;">
                <!--Tree-->
                <ul id="leftTree" class="nui-tree" style="width:100%;height:500px;background:#fafafa;marign:5px 0 0 0" 
                	url="com.atozsoft.wf.processManager.queryProcessClassTreeNode.biz.ext" dataField="data" 
                    showTreeIcon="true" resultAsTree="false" textField="text" idField="id" parentField="pid" onnodeselect="onNodeSelect" 
                    allowDrag="false" allowDrop="false" allowLeafDropIn="false" contextMenu="#treeMenu" expandOnLoad="true" >        
                </ul>	
            </div>
        </div>
        <div title="center" region="center" style="border:0;padding-left:5px;">
			<!--Tabs-->
            <div id="mainTabs" class="mini-tabs bg-toolbar" activeIndex="0" style="width:100%;height:100%;"      
                onactivechanged="onTabsActiveChanged">        
            </div>
	    </div>
	</div>
	
	<script type="text/javascript">
    	nui.parse();
    	//获取树结构
    	var tree = nui.get("leftTree");
    	//全部展开
    	//tree.expandAll();
    	//展开第一级树
    	tree.expandLevel(0);
    	tree.expandLevel(1);
		//Tab显示控制
        function showTab(node) {
            var tabs = nui.get("mainTabs");
            var id = "tab$" + node.id;
            var tab = tabs.getTab(id);
            if (!tab) {
                tab = {};
                tab._nodeid = node.id;
                var processDefID = node.id;
                
                var tabtitle = node.text;
                	var json =nui.encode({processDefID:processDefID});
		            $.ajax({
		                    url: "com.atozsoft.wf.processManager.queryProcessInfobyId.biz.ext",
		                    type: 'POST',
		                    data:json,
		                    cache: false,
		                    async: false,
		                    contentType: 'text/json',
		                    success: function(text) {
		                        var processInfo = nui.decode(text.data);
		                        tabtitle = processInfo.processChName;
		              }
		            });
                tab.title = tabtitle + "( V " + node.text + " )";
                tab.name  = id;
                tab.showCloseButton = true;
                //这里应该从后台直接获得完整的url地址
                tab.url = "<%=request.getContextPath()%>/wf/process/process_Info.jsp?processDefID=" + node.id;
                tabs.addTab(tab);
            }
            tabs.activeTab(tab);
        }

        function onNodeSelect(e) {
            var node = e.node;
            var isLeaf = e.isLeaf;
            //当点击的是节点时，显示TAB页面
            if (node.id !="2") {
                if (isLeaf !="0") {
                	showTab(node);
            	}
                //showTab(node);
            }
        }

        function onTabsActiveChanged(e) {
            var tabs = e.sender;
            var tab = tabs.getActiveTab();
            if (tab && tab._nodeid) {
                var node = tree.getNode(tab._nodeid);
                if (node && !tree.isSelectedNode(node)) {
                    tree.selectNode(node);
                }
            }
        }
    </script>
</body>
</html>